
//反转字符串中的单词(力扣151)
class Solution {
    public String reverseWords(String s) {
        StringBuilder yeah=removeSpace(s);
        reverseString(yeah,0,yeah.length()-1);
        reverseEachWords(yeah);
        return yeah.toString();

    }
    public StringBuilder removeSpace(String s){
        int start=0;
        int end=s.length()-1;
        while(s.charAt(start)==' '){
            start++;
        }
        while(s.charAt(end)==' '){
            end--;
        }
        StringBuilder jj=new StringBuilder();
        while(end>=start){
            char jb=s.charAt(start);
            if(jb!=' '||jj.charAt(jj.length()-1)!=' '){
                jj.append(jb);
            }
            start++;

        }
        return jj;

    }
    public void reverseString(StringBuilder yeah,int start,int end){
        while(end>start){
            char temp=yeah.charAt(end);
            yeah.setCharAt(end,yeah.charAt(start));
            yeah.setCharAt(start,temp);
            start++;
            end--;
        }


    }
    public void reverseEachWords(StringBuilder yeah){
        int start=0;
        int end=1;
        int n=yeah.length();
        while(end<n){
            while(end<n&&yeah.charAt(end)!=' '){
                end++;
            }
            reverseString(yeah,start,end-1);
            start=end+1;
            end=start+1;

        }
    }
}


//删除有序数组中的重复项 II(力扣80)
class Solution1 {
    public int removeDuplicates(int[] nums) {
        if(nums.length<=2){
            return nums.length;
        }
        int index=2;
        for(int i=2;i<nums.length;i++){
            if(nums[i]!=nums[index-2]){
                nums[index]=nums[i];
                index++;
            }
        }
        return index;
    }
}